$(function(){

    //会员章程
    var authActivity ={
    };
    /**
     * 初始化
     * **/
    authActivity.init = function(){
        $.ajax({
            async: false,
            url: '/authInfo/findAuthActivity',
            success: function (result) {
                if (result && result.code == 200) {
                    if (result.data != '') {
                       var $contentDiv = $('#content');
                       var content2 = '';
                       $.each( result.data ,function(key,auth){
                           if( key < 8 ){
                               content2 +='<div class="article-content-2">';
                               if( key%2==0){
                                   content2 +='<a href="/web/authActivityDetails?id='+auth.id+'"><img src="'+auth.url+'" alt="" class="imgItem"></a>';
                                   content2 +='<div class="article-content-rt"><span class="article-title article-title-2"><a href="/web/authActivityDetails?id='+auth.id+'" title="'+auth.title+'">'+auth.title+'</a></span>';
                                   content2 +='<span class="article-message">'+(auth.brief==null?"":auth.brief)+'</span>'
                                   content2 +='<time class="article-time-3">'+auth.createTime+'</time></div></div>';
                               }else{
                                   content2 +='<div class="article-content-rt"><span class="article-title article-title-2"><a href="/web/authActivityDetails?id='+auth.id+'" title="'+auth.title+'">'+auth.title+'</a></span>';
                                   content2 +='<span class="article-message">'+(auth.brief==null?"":auth.brief)+'</span>'
                                   content2 +='<time class="article-time-3">'+auth.createTime+'</time></div>';
                                   content2 +='<a href="/web/authActivityDetails?id='+auth.id+'"><img src="'+auth.url+'" alt="" class="imgItem"></a>';
                               }
                           }else{
                               content2 +='<div class="article-content-2 module-display-hide">';
                               if( key%2==0) {
                                   content2 += '<a href="/web/authActivityDetails?id=' + auth.id + '"><img src="' + auth.url + '" alt="" class="imgItem"></a>';
                                   content2 += '<div class="article-content-rt"><span class="article-title article-title-2"><a href="/web/authActivityDetails?id=' + auth.id + '" title="' + auth.title + '">' + auth.title + '</a></span>';
                                   content2 +='<span class="article-message">'+(auth.brief==null?"":auth.brief)+'</span>'
                                   content2 += '<time class="article-time-3">' + auth.createTime + '</time></div>';
                               }else{
                                   content2 += '<div class="article-content-rt"><span class="article-title article-title-2"><a href="/web/authActivityDetails?id=' + auth.id + '" title="' + auth.title + '">' + auth.title + '</a></span>';
                                   content2 +='<span class="article-message">'+(auth.brief==null?"":auth.brief)+'</span>'
                                   content2 += '<time class="article-time-3">' + auth.createTime + '</time></div>';
                                   content2 += '<a href="/web/authActivityDetails?id=' + auth.id + '"><img src="' + auth.url + '" alt="" class="imgItem"></a>';
                               }

                           }
                           content2 +='</div>';
                       });
                        $contentDiv.find('.article-content-2').remove();
                        $contentDiv.append(content2);
                        if( result.data.length >8 ){
                            $contentDiv.append('<button class="load-more">加载更多</button>');
                        }


                        $('.load-more').on('click',function(){
                            var maxShow = 4;
                            var moreBtn = $(this);
                            if($('.module-display-hide').length > 0){
                                $('.module-display-hide').each(function(index){
                                    if( index < maxShow )
                                        $(this).removeClass("module-display-hide");
                                });

                                //当没有需要加载的数据时
                                if($('.module-display-hide').length == 0){
                                    moreBtn.css("display","none");
                                }
                            }

                        });
                    }
                }
            },
            error: function () {
                layer.alert('服务器出错啦！', {icon: 2, title: '错误'});
            }
        });
    }

    //初始化
    authActivity.init();
    header.selLiCss("auth");
    //面包屑名称
    $("#menu-ico span").html("•&nbsp;&nbsp;会员俱乐部&nbsp;&nbsp;•&nbsp;&nbsp;会员活动");
});